package org.cyz.tools.common.util;

import org.cyz.tools.common.bean.DBInfo;
import org.cyz.tools.common.bean.Settings;
import org.cyz.tools.common.util.sqlite.SQLiteUtil;

/**
 * sql拼接工具
 */
public class InitDataUtil {
    public static final String UPDATE="UPDATE";
    public static final String CLIP="CLIP";
    public static final String LOAD_KEY="LOAD_KEY";


    static {
//        String sql="CREATE TABLE IF NOT EXISTS settings(id integer primary key,key varchar(20),value varchar(20))";
//        SQLiteUtil.execute(sql);
        SQLiteUtil.createTableIfNotExits(DBInfo.class);
        SQLiteUtil.createTableIfNotExits(Settings.class);
    }

    /**
     * 更新设置
     * @param key
     * @param selected
     * @return
     */
    public static boolean setUpdate(String key,String selected) {
        String sql="select * from settings where key='"+key+"'";
        Settings settings= (Settings) SQLiteUtil.find(sql,Settings.class);
        if(null!=settings){
//           return SQLiteUtil.setUpdate(key,selected);
        }else{
            //创建
//           return SQLiteUtil.insertSettings(key,selected);
        }
        return false;
    }


    /**
     * 获取对应的设置项
     * @param key
     * @return
     */
    public static Settings getSettings(String key) {
        String sql="select * from settings where key='"+key+"'";
        return (Settings) SQLiteUtil.find(sql,Settings.class);
    }
}
